package com.fishery.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fishery.base.entity.Supply;
import com.fishery.base.mapper.SupplyMapper;
import com.fishery.base.service.SupplyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Ghost
 * @since 2021-01-15
 */
@Service
public class SupplyServiceImpl extends ServiceImpl<SupplyMapper, Supply> implements SupplyService {

	@Autowired
	private SupplyMapper supplyMapper;

	@Override
	public Page<Supply> getSupplyWithPage(int size, int current) {
		if (size <= 0) {
			size = 5;
		}
		if (current <= 0) {
			current = 1;
		}
		Page<Supply> page = new Page<>(current, size);
		supplyMapper.selectPage(page, null);
		return page;
	}

	@Override
	public List<Supply> getAllSuppliesByType(Integer type) {
		QueryWrapper wrapper = new QueryWrapper();
		wrapper.eq("type", type);
		return supplyMapper.selectList(wrapper);
	}

	@Override
	public Supply traceSupplyInformation(String supplyId) {
		return supplyMapper.findSupplyEvenDelete(supplyId);
	}
}
